﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace LbangCMS.Extensions
{
    public static class ImageHelper
    {
        public static MvcHtmlString Img(this HtmlHelper htmlHelper, string src, string id = "", string title = "", string cssClas = "")
        {
            if (!src.StartsWith("http"))
            {
                var imageDomain = System.Configuration.ConfigurationManager.AppSettings["ImageDomain"];
                if (!string.IsNullOrEmpty(imageDomain))
                {
                    imageDomain = imageDomain.EndsWith("/") == true ? imageDomain.TrimEnd('/') : imageDomain;
                    if (!src.StartsWith("/"))
                    {
                        src = "/" + src;
                    }
                    src = imageDomain + src;
                }
            }
            return MvcHtmlString.Create(string.Format("<img src='{0}' id='{1}' title='{2}' class='{3}'/>", src, id, title, cssClas));
        }
    }
}
